package com.hr.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hr.dao.DepartmentDao;
import com.hr.dao.UserDao;
import com.hr.model.DepartmentModel;
import com.hr.model.DialogModel;
import com.hr.model.UserModel;
import com.hr.service.DialogService;
@Service
public class DialogServiceImpl implements DialogService{
	@Autowired
	private UserDao userDao;
	@Autowired
	private DepartmentDao departmentDao;

	@Override
	public List<DialogModel> generateModel(String type) {
		List<DialogModel> dialogModels = new ArrayList<DialogModel>();
		if("department".equals(type)){
			List<DepartmentModel>  departmentModels = departmentDao.queryAll();
			for(DepartmentModel department:departmentModels){
				DialogModel dialogModel = new DialogModel();
				dialogModel.setCode(department.getCode());
				dialogModel.setValue(department.getName());
				dialogModels.add(dialogModel);
			}
		}else if("user".equals(type)){
			List<UserModel>  userModels = userDao.findAll();
			for(UserModel userModel:userModels){
				DialogModel dialogModel = new DialogModel();
				dialogModel.setCode(userModel.getUser_id());
				dialogModel.setValue(userModel.getName());
				dialogModels.add(dialogModel);
			}
		}
		return dialogModels;
	}
	
}
